home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Ghost 1.0 / source / Ghost ƒ / Ghost code / ghost end.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  4.2 KB  |  196 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        ghost end.c
  4.  
  5. Purpose:    This module handles ending a player's turn (adding a
  6.             letter), stepping to the next player, and ending a round
  7.             (when appropriate).
  8.  
  9.  
  10. Ghost -=- a classic word-building challenge
  11. Copyright (C) 1993 Mark Pilgrim
  12.  
  13. This program is free software; you can redistribute it and/or modify
  14. it under the terms of the GNU General Public License as published by
  15. the Free Software Foundation; either version 2 of the License, or
  16. (at your option) any later version.
  17.  
  18. This program is distributed in the hope that it will be useful,
  19. but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  21. GNU General Public License for more details.
  22.  
  23. You should have received a copy of the GNU General Public License
  24. along with this program in a file named "GNU General Public License".
  25. If not, write to the Free Software Foundation, 675 Mass Ave,
  26. Cambridge, MA 02139, USA.
  27.  
  28. \**********************************************************************/
  29.  
  30. #include "ghost globals.h"
  31. #include "ghost end.h"
  32. #include "ghost strategy.h"
  33. #include "ghost challenge.h"
  34. #include "msg graphics.h"
  35. #include "msg dialogs.h"
  36. #include "msg environment.h"
  37. #include "msg timing.h"
  38. #include "msg sounds.h"
  39.  
  40. void AddLetter(char theChar)
  41. {
  42.     if (theChar==' ')
  43.     {
  44.         TimeCorrection(1+30*gGameSpeed);
  45.         StartTiming();
  46.         ChallengeWord();
  47.     }
  48.     else
  49.     {
  50.         gTheWord[++gTheWord[0]]=theChar;
  51.         TimeCorrection(1+30*gGameSpeed);
  52.         StartTiming();
  53.         DoSound(sound_play_letter, TRUE);
  54.         gStatus=kNewPlayer;
  55.         UpdateBoard();
  56.         gStatus=kNoStatus;
  57.         NextPlayer();
  58.     }
  59. }
  60.  
  61. void NextPlayer(void)
  62. {
  63.     FindStartPtr(TRUE);
  64.     if (gTheWord[0]>=0x04)
  65.     {
  66.         GetNextWord(FALSE);
  67.         if (thisWord[0]==gTheWord[0])
  68.             EndRound();
  69.     }
  70.     
  71.     GoToNextPlayer();
  72.     
  73.     UpdateBoard();
  74. }
  75.  
  76. void GoToNextPlayer(void)
  77. {
  78.     Boolean            keepgoing;
  79.     
  80.     do
  81.     {
  82.         gCurrentPlayer++;
  83.         if (gCurrentPlayer==gNumPlayers)
  84.             gCurrentPlayer=0;
  85.         if (gPlayOrderIndex[gCurrentPlayer]>=gNumHumanPlayers)
  86.             keepgoing=(gComputerPlayerScore[gPlayOrderIndex[gCurrentPlayer]-gNumHumanPlayers]==5);
  87.         else
  88.             keepgoing=(gHumanPlayerScore[gPlayOrderIndex[gCurrentPlayer]]==5);
  89.     }
  90.     while (keepgoing);
  91. }
  92.  
  93. void GoToPreviousPlayer(void)
  94. {
  95.     Boolean            keepgoing;
  96.     
  97.     do
  98.     {
  99.         gCurrentPlayer--;
  100.         if (gCurrentPlayer<0)
  101.             gCurrentPlayer=gNumPlayers-1;
  102.         if (gPlayOrderIndex[gCurrentPlayer]>=gNumHumanPlayers)
  103.             keepgoing=(gComputerPlayerScore[gPlayOrderIndex[gCurrentPlayer]-gNumHumanPlayers]==5);
  104.         else
  105.             keepgoing=(gHumanPlayerScore[gPlayOrderIndex[gCurrentPlayer]]==5);
  106.     }
  107.     while (keepgoing);
  108. }
  109.  
  110. void EndRound(void)
  111. {
  112.     int                index;
  113.     
  114.     index=gPlayOrderIndex[gCurrentPlayer];
  115.     if (index>=gNumHumanPlayers)
  116.         gComputerPlayerScore[index-gNumHumanPlayers]++;
  117.     else
  118.         gHumanPlayerScore[gPlayOrderIndex[gCurrentPlayer]]++;
  119.     
  120.     gStatus=kJustGotALetter;
  121.     UpdateBoard();
  122.     gStatus=kNoStatus;
  123.     
  124.     if (gPlayOrderIndex[gCurrentPlayer]>=gNumHumanPlayers)
  125.         TimeCorrection(1+30*gGameSpeed);
  126.     StartTiming();
  127.  
  128.     if (gPlayOrderIndex[gCurrentPlayer]>=gNumHumanPlayers)
  129.     {
  130.         if (gComputerPlayerScore[gPlayOrderIndex[gCurrentPlayer]-gNumHumanPlayers]==5)
  131.             ComputerLoses();
  132.     }
  133.     else
  134.     {
  135.         if (gHumanPlayerScore[gPlayOrderIndex[gCurrentPlayer]]==5)
  136.             HumanLoses();
  137.     }
  138.     
  139.     if (gInProgress)
  140.     {
  141.         if (gPlayOrderIndex[gCurrentPlayer]<gNumHumanPlayers)
  142.         {
  143.             TimeCorrection(1+30*gGameSpeed);
  144.             StartTiming();
  145.         }
  146.         gTheWord[0]=0x00;
  147.         oldStartPtr=startPtr=listPtr=0L;
  148.         gCurrentPlayer--;
  149.     }
  150. }
  151.  
  152. void HumanLoses(void)
  153. {
  154.     gStatus=kJustLost;
  155.     UpdateBoard();
  156.     gStatus=kNoStatus;
  157.     
  158.     TimeCorrection(1+30*gGameSpeed);
  159.     StartTiming();
  160.  
  161.     gActualHumanPlayers--;
  162.     if (gActualHumanPlayers+gActualComputerPlayers==1)
  163.     {
  164.         DoSound(sound_joy, TRUE);
  165.         gInProgress=FALSE;
  166.     }
  167.     else DoSound(sound_raz, FALSE);
  168. }
  169.  
  170. void ComputerLoses(void)
  171. {
  172.     int                iconIndex;
  173.     
  174.     gStatus=kJustLost;
  175.     UpdateBoard();
  176.     gStatus=kNoStatus;
  177.     
  178.     gActualComputerPlayers--;
  179.     if (gActualHumanPlayers+gActualComputerPlayers==1)
  180.     {
  181.         DoSound(sound_joy, TRUE);
  182.         gInProgress=FALSE;
  183.     }
  184.     else
  185.     {
  186.         iconIndex=gComputerIconIndex[gPlayOrderIndex[gCurrentPlayer]-gNumHumanPlayers];
  187.         if ((iconIndex==0) || (iconIndex==2) || (iconIndex==22))
  188.             DoSound(sound_female_shoot, FALSE);
  189.         else
  190.             DoSound(sound_male_shoot, FALSE);
  191.     }
  192.  
  193.     TimeCorrection(1+30*gGameSpeed);
  194.     StartTiming();
  195. }
  196.